var $ = getApp(), methods = require("../methods.js");
Page(Object.assign({}, methods, {
	data: {
		haspwd: 0,
	},
	_onLoad: function (options) {
		var that = this
		$.get('my/paypwd',{},function(data){
			that.setData({haspwd:data.haspwd})
		})
	},
	formSubmit: function (e) {
		var formdata = e.detail.value;
		if (this.data.haspwd == 1) {
			if (formdata.oldpaypwd == '') {
				$.alert('请输入原密码'); return;
			}
			//if (formdata.oldpaypwd != this.data.userinfo['paypwd']) {
			//	$.alert('原密码输入错误'); return;
			//}
		}else{
			formdata.oldpaypwd = '';
		}
		if (formdata.paypwd == '') {
			$.alert('请输入新密码'); return;
		}
		if (formdata.paypwd.length < 6) {
			$.alert('新密码不小于6位'); return;
		}
		if (formdata.repaypwd == '') {
			$.alert('请再次输入新密码'); return;
		}
		if (formdata.paypwd != formdata.repaypwd) {
			$.alert('两次密码不一致'); return;
		}
		$.post("my/paypwd", { formdata: { oldpaypwd:formdata.oldpaypwd,paypwd: formdata.paypwd } }, function (data) {
			if(data.status==1){
				$.success(data.msg);
				setTimeout(function () {
					$.goback();
				}, 1000)
			}else{
				$.error(data.msg);	
			}
		}, '提交中')
	}
}))